package com.im.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitmqConfig {

    public static final String IM_EXCHANGE = "im_exchange";
    public static final String IM_SERVICE = "im_service";

    //声明交换机
    @Bean(IM_EXCHANGE)
    public Exchange IM_EXCHANGE() {
        //durable(true) 持久化，mq重启之后交换机还在
        return ExchangeBuilder.topicExchange(IM_EXCHANGE).durable(true).build();
    }

    //声明IM_SERVICE队列
    @Bean(IM_SERVICE)
    public Queue IM_SERVICE() {
        return new Queue(IM_SERVICE);
    }

    //IM_SERVICE队列 绑定 IM_EXCHANGE交换机，指定routingKey
    @Bean
    public Binding BINDING_ROUTING(@Qualifier(IM_SERVICE) Queue queue,
                                   @Qualifier(IM_EXCHANGE) Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("").noargs();
    }

}